﻿using Dapper;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using YinfangWeb.Model;

namespace YinfangWeb.DAL
{
    public partial class OrderCartDAO
    {
        #region 获取用户购物车的全部商品列表
        public List<dynamic> GetList(int UserID)
        {
            var sql = $@"SELECT oc.*,pp.*,pd.ProductName,pf.FileName FROM OrderCart oc 
		JOIN ProductParam pp ON pp.ProductParamID=oc.ProductParamID 
		JOIN ProductData pd ON pp.ProductDataID=pd.ProductDataID
		JOIN ProductFile pf ON pf.ProductFileID=pp.DefaultProductFileID
	WHERE oc.RegUserID={UserID} ORDER BY OrderCartID DESC";
            using (var conn = ConnectionFactory.CreateConnection())
            {
                var q = conn.Query<dynamic>(sql);
                return q.ToList();
            }
        }
        #endregion
        #region 获取用户在购物车的指定单条商品
        public OrderCart GetInfo(int UserID, int MerchantID, int ProductParamID)
        {
            var sql = $"SELECT * FROM OrderCart WHERE CartState=1 AND RegUserID={UserID} AND MerchantDataID={MerchantID} AND ProductParamID={ProductParamID}";
            using (var conn = ConnectionFactory.CreateConnection())
            {
                var model = conn.QueryFirstOrDefault<OrderCart>(sql);
                return model;
            }
        }
        #endregion
    }
}
